<?php

/**
 * @author Walter Tamboer
 */
 
/**
 * Send an e-mail.
 */
class Email
{
	private $Subject;

	private $Message;

	private $To;

	private $From;

	private $AttachmentList;
	
	private $Headers = array();
	
	private $AdditionalParams;

	public function __construct()
	{
		$this->AttachmentList = array();
		//$this->Headers = 'From: webmaster@example.com' . "\r\n" .
			//'Reply-To: no-repl' . "\r\n" .
		//	'X-Mailer: PHP/' . phpversion();
		$this->Headers[ 'X-Mailer' ] = 'PHP/' . phpversion();
		$this->AdditionalParams = null;
	}

	public function SetSubject($Value)
	{
		$this->Subject = $Value;
	}

	public function SetMessage($Value)
	{
		$this->Message = $Value;
	}

	public function SetTo($Value)
	{
		$this->To = $Value;
	}

	public function SetFrom($Value)
	{
		//$this->From = $Value;
		$this->AddHeader( 'From', $Value );
	}

	public function AddHeader( $Name, $Value )
	{
		$this->Headers[ $Name ] = $Value;
	}

	public function AddAttachment($filepath)
	{
		$this->AttachmentList[] = $filepath;
	}

	public function Send()
	{
		$Headers = '';
		
		foreach( $this->Headers as $HeaderName => $HeaderValue )
		{
			if( is_string( $HeaderValue ) && $HeaderValue != '' && is_string( $HeaderName ) && $HeaderName != '' )
			{
				$Headers .= $HeaderName . ': ' . $HeaderValue . "\r\n";
			}
		}
		
		return @mail($this->To, $this->Subject, $this->Message, $Headers);
	}
	
	public function __toString()
	{
		return $this->Message;
	}
}

?>